home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Hyper Stacks 1994 May
/
Hyper Stacks (Pacific HiTech)(1994)[Mac].iso
/
XCMDS&XFCNS
/
Shifting Priorities
/
card_2988.txt
< prev
next >
Wrap
Text File
|
1994-05-01
|
13KB
|
334 lines
-- card: 2988 from stack: in
-- bmap block id: 0
-- flags: 0000
-- background id: 2679
-- name:
-- part 1 (field)
-- low flags: 25
-- high flags: 0007
-- rect: left=27 top=28 right=324 bottom=484
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 0
-- font id: 16
-- text size: 10
-- style flags: 0
-- line height: 13
-- part name: Priorities
----- HyperTalk script -----
-- ShiftingPriorities
--
-- A self-contained field script to easily rearrange lines in fields:
--
-- Shift-click near any corner to resize.
-- Shift-click near the center to relocate.
-- Option-click to change text size.
-- Command-click to modify text attributes.
-- Click and hold on a line to select and move it.
-- Single-click to open the field for editing.
--
-- This field must have its textLock and dontWrap properties set,
-- and must be a scrolling field. Simple clone-and-go feature.
--
-- © 1992 Douglas Parker & Maccyx. All rights reserved.
--
-- This script may be circulated freely, provided these comments
-- remain unaltered.
--
----------------------------------------------------------------------
on mouseDown
if the optionKey is down then
put "*" into it -- a dummy value
repeat until it is a number or theResult is "Cancel"
ask "Change the text to which point size?" with the textSize of me
put the result into theResult
put it into theIt
-- make sure it's a valid response
if it is a number and it is not empty and theResult is not "Cancel" then
set the textSize of me to it
else if theResult is not "Cancel" then
beep
answer "That is not a number" with "OK"
-- put the result into it
end if
end repeat
else if the shiftKey is down then
-- we're going to move or rearrange things here
put item one of the mouseLoc into xMouse
put item two of the mouseLoc into yMouse
put item one of the loc of me into xField
put item two of the loc of me into yField
-- divide the field into a 3x3 matrix, then test for
-- the mouse being in the center region.
if (abs(xField - xMouse) < the width of me/6) and (abs(yField - yMouse) < the width of me/6) then
repeat until the mouse is up
set the loc of me to the mouseLoc -- move me around
end repeat
else
put the width of me into myWidth
put the height of me into myHeight
-- similarly, divide the field into a 6x6 matrix. If the
-- mouse is down inside the corner 1/36th area, then resize
-- Hmm, now why did he choose 1/36th?
if (abs(xField - xMouse) > myWidth/2 - myWidth/6) and (abs(yField - yMouse) > myHeight/2 - myHeight/6) then
put the rect of me into theOriginalRect
repeat until the mouse is up -- resize me by the corners
if item 1 of the mouseLoc > item 1 of the loc of me and item 2 of the mouseLoc < item 2 of the loc of me then
-- quadrant 1 top right
repeat until the mouse is up
put the rect of me into newRect
put item one of the mouseLoc into item 3 of newRect
put item two of the mouseLoc into item 2 of newRect
set the rect of me to newRect
end repeat
else if item 1 of the mouseLoc < item 1 of the loc of me and item 2 of the mouseLoc < item 2 of the loc of me then
--quadrant 2 top left
repeat until the mouse is up
put the rect of me into newRect
put item one of the mouseLoc into item 1 of newRect
put item two of the mouseLoc into item 2 of newRect
set the rect of me to newRect
end repeat
else if item 1 of the mouseLoc < item 1 of the loc of me and item 2 of the mouseLoc > item 2 of the loc of me then
-- quadrant 3 bottom left
repeat until the mouse is up
put the rect of me into newRect
put item one of the mouseLoc into item 1 of newRect
put item two of the mouseLoc into item 4 of newRect
set the rect of me to newRect
end repeat
else
-- quadrant 4 bottom right
repeat until the mouse is up
put the rect of me into newRect
put item one of the mouseLoc into item 3 of newRect
put item two of the mouseLoc into item 4 of newRect
set the rect of me to newRect
end repeat
end if
end repeat
-- but you can't make it too small...
if the height of me ≤ 30 or the width of me ≤ 60 then
beep
set the rect of me to theOriginalRect
end if
end if
end if
else if the commandKey is down then
-- bring up the text attribute dialog box...
lock Screen
set cursor to watch
put the userlevel into theUserlevel
set the userlevel to 5
choose field tool
click at the loc of me
type "t" with commandKey
set the userlevel to theUserlevel
choose browse tool
unlock Screen
set cursor to hand
else
global lastTick
put the ticks into lastTick
end if
pass mouseDown
end mouseDown
on mouseStillDown
global lastMSD, lastTick
put the ticks into thisMSD
put word 2 of the clickLine into theClickLine
put the number of lines of me into theLineCount
-- The mouse*Up* handler for this field uses a "click at" command.
-- Side effects of the click at command include a "mouseDown",
-- ten "mouseStillDown"s, and "mouseUp" system messages to be
-- issued--as if the mouse is being clicked very slowly. These
-- unwanted mouseStillDowns are intercepted, but discarded by
-- setting the value of N on the line
-- if thisMSD - lastMSD ‚â• N then
-- to some value shorter than the repeating execution time
-- of the user's mouseStillDown script, yet large enough that
-- the unwanted mouseStillDowns are filtered out.
--
-- The line also prevents execution of the remaining part of the
-- handler if the user clicks in white space beyond the last line.
if (thisMSD - lastMSD ≥ 60) and (theClickLine ≤ theLineCount) then
put the ticks into lastMSD -- for next time
put line word two of the clickLine of me into holdLine -- preprocessing
put the scroll of me into theScroll -- I'm going to lose the scroll soon
-- this section calculates the lineHeight in pixels, not points,
-- and sets some constants to speed up the repeat loop
lock Screen -- don't want 'em to see the fields shifting...
put the top of me into theTopOfMe -- preprocessing
if the wideMargins of me then -- evaluates to if true then
put 4 into marginWidth -- all textHeights use a wide margin of 4
else
put 0 into marginWidth
end if
select char 1 to 0 of line 1 of me -- this can modify the scroll
put item 2 of the selectedLoc - theTopOfMe - marginWidth - 1 into thePixelHeight -- all to find out the pixel height per line.
-- -- It can vary.
select empty -- hide the text cursor
-- this resets the original scroll in case the select line changed it
set scroll of me to theScroll
unlock Screen
-- making theDragLine equal to theClickLine won't move it
-- the first time through the repeat
put min(theLineCount,theClickLine) into theDragLine -- theDragLine needs a value
put (the top of me + marginWidth + 1) into theFactor -- preprocessing
-- If the mouse is held down just long enough to enter this hander
-- AND just long enough to go through the repeat loop once, there
-- may be too much time between the user's lastTick from the
-- mouseDown and the execution of the mouseUp handler to place the
-- I-beam when that is the intention. This next
-- line is here *just in case* this happens. It also smooths out
-- the execution of the I-beam insertion in the field.
put the ticks into lastTick
-- This next two lines can be moved inside the repeat loop.
-- If they are moved inside the repeat, the cursor won't change
-- until the text is *really* ready to move as the user holds
-- the mouse down. One side effect of this will be a flashing
-- cursor as the set cursor command is repeatedly executed.
-- If-then-elses could be used to assure one-shot operation,
-- but would slow down the loop speed. NB: The loop has to be
-- optimized for speed to make the screen moves follow the
-- mouse closely.
set cursor to arrow -- prepare to move
set the textStyle of line word two of the clickLine of me to bold
repeat while the mouse is down
wait for 5 ticks -- keep from selecting adjacent lines every time
-- this follows the mouse around the screen, calculating line numbers
put trunc((item two of the mouseLoc + theScroll - theFactor)/ (thePixelHeight)) + 1 into theDragLine
put max(1,min(theLineCount,theDragLine)) into theDragLine
if theClickLine ≠ theDragLine and theClickLine ≤ theLineCount then
-- theClickLine is the destination
-- theDragLine is the source
lock Screen -- make it pretty!
delete line theClickLine of me
put holdLine & return before line theDragLine of me
-- Beyon the top or bottom? Scroll the field appropriately.
if item 2 of the mouseLoc ‚â• the bottom of me then
put theScroll + thePixelHeight into theScroll
else if item 2 of the mouseLoc ≤ the top of me then
put theScroll - thePixelHeight into theScroll
end if
set scroll of me to theScroll
set the textStyle of line theDragLine of me to bold
-- use a visual effect in the next line to give
-- a different feel & look.
unlock Screen -- with dissolve -- aah! that feels better...
end if
put theDragLine into theClickLine
end repeat
set the textStyle of line theClickLine of me to plain
end if
pass mouseStillDown
end mouseStillDown
on closeField
-- Get rid of unnecessary null lines at the end of the field.
-- The user can't see them and usually creates plenty of them
-- as they click once within the white space at the end of the
-- field.
repeat while the last line of me is empty and the number of lines of me ‚â• 1
delete the last line of me
end repeat
set the lockText of me to true
pass closeField
end closeField
on exitField
-- Get rid of unnecessary null lines at the end of the field.
-- The user can't see them and usually creates plenty of them
-- as they click once within the white space at the end of the
-- field.
repeat while the last line of me is empty and the number of lines of me ‚â• 1
delete the last line of me
end repeat
set the lockText of me to true
send "closeField" to me
pass exitField
end exitField
on mouseUp
global lastTick
-- Your value may vary. 45 ticks works for an SE/30. The
-- difference measures the time between the mouseDown and
-- this mouseUp, --or-- between the first iteration of the
-- mouseStillDown repeat loop and this mouseUp.
-- Too many single clicks make the I-beam appear? Decrease the value.
-- Not enough single clicks bring the I-beam? Increase the value.
if (the ticks - lastTick ≤ 45) then
set the lockText of me to false
click at the clickLoc
end if
put the ticks into lastTick
pass mouseUp
end mouseUp
-- part contents for card part 1
----- text -----
Press Tab, press Enter, or click outside the field to get back the browse tool.
Add a period to the end of this line
<Return> works within the field. It doesn't work like Tab or Enter.
Change the text size to 12 point—(option-click with the browse tool)
Try to change text size to an erroneous value!
The field has to be a scrolling field.
Remember to set the “lockText” of any new fields you create.
Be sure to set the “Don't Wrap” attribute -- or else! :-)
Command-click with the browse tool to change text characteristics.
Try to double-click on a word.
Hold the mouse button down on this line. Drag it around the field.
The best double click technique is: single-click (pause) single-click.
Shift-click near the *center* to move the field.
Shift-click near the corners to resize the field.
Resize too small and you'll get a beep and the field size will restore.
Put lots o’ lines in the field and try to drag beyond the top or the bottom edge.
Scrolling works properly!
Happy Scripting. Drop me a note if you like it.
Douglas Parker
45090 Elmhurst Ct.
Utica, MI 48317-4991
Freeware.